﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace calculator
{
    class BinaryString
    {
        public string getBinaryString(int numberToConvert)//Converts an integer into its binary counterpart
        {
            if (numberToConvert < 0)
                throw new ArgumentException("The integer can't be less then 0");//ArgumentException is used to indicate that there is something wrong with the input.

            string binary = Convert.ToString(numberToConvert, 2);
            return binary;
        }

        public string addTrailingZeros(int lengthOfString, int numberToConvert)//This adds 0's to the begining of the string, using the length of the string you want 
        {
            string binary = getBinaryString(numberToConvert);//This gives us the numberToConvert binary form
            string zerosToAddToBinary = "";//This will be the string of 0's that will be added at the beginning of the binary string

            lengthOfString = lengthOfString - binary.Length;//This figures out how many 0's we need to add to the string

            for (int i = 0; i < lengthOfString; i++)
            {
                zerosToAddToBinary += "0";
            }

            return (zerosToAddToBinary + binary).ToString();//Combines the 0's and the binary number into one string
        }

        public string flipBits(string numberToConvert)//A function that simply flips all ones in a string to zero's and all zero's to one's
        {
            if (numberToConvert == null)
                throw new ArgumentNullException("Can't pass into the function null");
            else if (numberToConvert == "")
                throw new ArgumentException("The string can't be empty");
            string flipedBinary = "";
            foreach (char letter in numberToConvert)
            {
                if (letter == '0')
                    flipedBinary += '1';
                else if (letter == '1')
                    flipedBinary += '0';
            }
            return flipedBinary;
        }
    }
}
